package controllers;

import java.io.IOException;

import boundarys.AssociateProductGUI;
import ccrm.ClientMain;
import entitys.Category;
import entitys.Product;
import entitys.ProductInType;
import entitys.Request;
import entitys.Session;
import entitys.Type;
import enums.Command;

public class AssociateProductController {
	AssociateProductGUI apc;

	public AssociateProductController(AssociateProductGUI ap)
	{
		this.apc=apc;
	}
	
	/**
	 * sends request to server to get association list
	 */
	public static void getTrio()
	{
		Request r =new Request(Command.GET_TRIO,Session.getEmployee().getUserId());
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
 
	}

	/**
	 * sends request to server to add new association to the database
	 * @param productid
	 * @param typeid
	 * @param categoryid
	 */
	public static void associateProduct(int productid, int typeid, int categoryid) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.ASSOCIATE_PRODUCT,Session.getEmployee().getUserId(),new ProductInType(productid, typeid, categoryid));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	/**
	 * sends request to server to delete association
	 * @param pid
	 * @param tid
	 * @param cid
	 */
	public static void deleteAssociation(int pid, int tid, int cid) {
		// TODO Auto-generated method stub
		Request r =new Request(Command.DELETE_ASSOCIATION,Session.getEmployee().getUserId(), new ProductInType(pid, tid, cid));
		
		try {
			ClientMain.client.sendToServer(r);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
